<template>
  <div>
    <ul>
      <li v-for="m in messageList" :key="m.id">
        <!--传递params参数，需要在index.js中配置-->
        <!--        <router-link :replace="true" :to="`/home/message/detail/${m.id}/${m.title}`">{{ m.title }}</router-link>-->

        <!--         传递params参数必须使用name不能使用path-->
        <router-link :to="{
            name:'myDetail',
            params:{
               id:m.id,
               title:m.title
            }
        }">
          {{ m.title }}
        </router-link>
        <button type="button" class="btn btn-primary btn-xs" @click="pushShow(m)">push查看</button>
        <button type="button" class="btn btn-default btn-xs" @click="replaceShow(m)">replace查看</button>
      </li>
    </ul>
    <hr>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "Message",
  data() {
    return {
      messageList: [
        {id: '001', title: '消息001'},
        {id: '002', title: '消息002'},
        {id: '003', title: '消息003'}
      ]
    }
  },
  methods: {
    pushShow(m) {
      // 采用push方式跳转
      this.$router.push({
        name: 'myDetail',
        params: {
          id: m.id,
          title: m.title
        }
      });
    },
    replaceShow(m) {
      // 采用replace方式跳转
      this.$router.replace({
        name: 'myDetail',
        params: {
          id: m.id,
          title: m.title
        }
      });
    }
  }
}
</script>

<style scoped>

</style>